/*
 * @Description:具有动画效果的弹框
 * @Author: tao.xie
 * @Date: 2019-03-28 09:51:48
 * @Last Modified by: tao.xie
 * @Last Modified time: 2019-04-02 17:47:58
 */
<template>
  <div>
    <transition
      name="fade"
      v-on:after-leave="leave"
      v-on:after-enter="enter"
    >
      <div
        class="wrapper flex-v flex-vc flex-hc"
        v-if="isShow"
      >
        <slot />
      </div>
    </transition>
  </div>
</template>

<script>
export default {
  methods: {
    hide() {
      this.isShow = false
    },
    show() {
      this.isShow = true
    },
    leave: function () {
      document.body.removeChild(this.$el)
      // 启用body的滚动条
      document.body.style.overflow = 'auto'
    },
    enter: function () {
      // 禁用body的滚动条
      document.body.style.overflow = 'hidden'
    }
  },
  data() {
    return {
      isShow: false
    }
  }
}
</script>

<style scoped>
.wrapper {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  bottom: 0;
  z-index: 999;
  background: rgba(0, 0, 0, 0.4);
}

/* 弹框的动画效果 */
.fade-enter-active {
  animation: fade-in 0.2s;
}
.fade-leave-active {
  animation: fade-in 0.2s reverse;
}
@keyframes fade-in {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}
</style>
